package cn.pconline.officialclub.entity;

import cn.pconline.autoclub.entity.User;
import com.alibaba.fastjson.annotation.JSONField;
import java.util.Date;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Id;
import org.gelivable.dao.Mid;
import org.gelivable.dao.Transient;

/**
 * 普通会员加入官方车友会关系表
 *
 * @author <a href="mailto:chensy0203@163.com">chensy</a>
 */
@Entity(tableName = "oac_common_member")
public class OCommonMember extends EntityKit implements EntityWithUser {

    /**
     * 用户id
     */
    @Id
    @Column(name = "user_id")
    private long userId;
    /**
     * 官方车友会id
     */
    @Id
    @Column(name = "o_club_id")
    private long oClubId;
    /**
     * 加入时间
     */
    @Column(name = "join_at")
    private Date joinAt;
    /**
     * 是否管理员,0:无职务,1:副会长,2:会长
     */
    @Column(name = "admin_type")
    private int adminType;
    /**
     * 无职务
     */
    public static final int ADMIN_TYPE_COMMON = 0;
    /**
     * 副会长
     */
    public static final int ADMIN_TYPE_VICE_PRESIDENT = 1;
    /**
     * 会长
     */
    public static final int ADMIN_TYPE_PRESIDENT = 2;
    @Transient
    @JSONField(serialize = false, deserialize = false)
    private User user;

    /**
     * 是否是管理员（会长|副会长）
     *
     * @return
     */
    public boolean isAdmin() {
        return adminType == ADMIN_TYPE_PRESIDENT || adminType == ADMIN_TYPE_VICE_PRESIDENT;
    }
    /**
     * 是否会长
     * @return 
     */
    public boolean isPresident(){
         return adminType == ADMIN_TYPE_PRESIDENT;
    }
    /**
     * 是否副会长
     * @return 
     */
    public boolean isVicePresident(){
        return adminType == ADMIN_TYPE_VICE_PRESIDENT;
    }
    @Override
    public long getUserId() {
        return userId;
    }

    @Override
    public void setUserId(long userId) {
        this.userId = userId;
    }

    /**
     * 兼容geli
     *
     * @return
     */
    public long getOClubId() {
        return oClubId;
    }

    /**
     * 兼容geli
     *
     * @return
     */
    public void setOClubId(long oClubId) {
        this.oClubId = oClubId;
    }

    public long getoClubId() {
        return oClubId;
    }

    public void setoClubId(long oClubId) {
        this.oClubId = oClubId;
    }

    public Date getJoinAt() {
        return joinAt;
    }

    public void setJoinAt(Date joinAt) {
        this.joinAt = joinAt;
    }

    public int getAdminType() {
        return adminType;
    }

    public void setAdminType(int adminType) {
        this.adminType = adminType;
    }

    @Override
    public User getUser() {
        return this.user;
    }

    @Override
    public void setUser(User user) {
        this.user = user;
    }

    public Mid getId() {
        return new Mid(userId, oClubId);
    }
}
